// 生成时间序列数据
export const generateTimeSeriesData = (days: number = 7) => {
  const data = []
  const now = new Date()
  const oneDay = 24 * 60 * 60 * 1000

  for (let i = days - 1; i >= 0; i--) {
    const date = new Date(now.getTime() - i * oneDay)
    const baseValue = 2000 + Math.random() * 1000
    const hourlyData = []

    for (let hour = 0; hour < 24; hour++) {
      const value = baseValue + Math.sin(hour / 24 * Math.PI * 2) * 500 + (Math.random() - 0.5) * 200
      hourlyData.push({
        time: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(hour).padStart(2, '0')}:00`,
        value: Math.round(value)
      })
    }

    data.push(...hourlyData)
  }

  return data
}

// 生成能耗分布数据
export const generateEnergyDistributionData = () => {
  return [
    { name: '空调系统', value: 45 },
    { name: '照明系统', value: 20 },
    { name: '实验设备', value: 25 },
    { name: '通风系统', value: 10 }
  ]
}

// 生成预测数据
export const generatePredictionData = (days: number = 7) => {
  const actualData = generateTimeSeriesData(days)
  return actualData.map(item => ({
    ...item,
    predicted: Math.round(item.value * (1 + (Math.random() - 0.5) * 0.1))
  }))
}

// 生成设备能耗数据
export const generateDeviceEnergyData = () => {
  return [
    {
      name: '空调主机',
      data: Array.from({ length: 24 }, (_, i) => ({
        time: `${String(i).padStart(2, '0')}:00`,
        value: Math.round(2000 + Math.sin(i / 24 * Math.PI * 2) * 500)
      }))
    },
    {
      name: '照明系统',
      data: Array.from({ length: 24 }, (_, i) => ({
        time: `${String(i).padStart(2, '0')}:00`,
        value: Math.round(800 + Math.sin(i / 24 * Math.PI * 2) * 200)
      }))
    },
    {
      name: '实验设备',
      data: Array.from({ length: 24 }, (_, i) => ({
        time: `${String(i).padStart(2, '0')}:00`,
        value: Math.round(1500 + Math.sin(i / 24 * Math.PI * 2) * 300)
      }))
    }
  ]
}

// 生成温度数据
export const generateTemperatureData = (days: number = 7) => {
  const data = []
  const now = new Date()
  const oneDay = 24 * 60 * 60 * 1000

  for (let i = days - 1; i >= 0; i--) {
    const date = new Date(now.getTime() - i * oneDay)
    const baseTemp = 24 + Math.random() * 2
    const hourlyData = []

    for (let hour = 0; hour < 24; hour++) {
      const temp = baseTemp + Math.sin(hour / 24 * Math.PI * 2) * 2 + (Math.random() - 0.5)
      hourlyData.push({
        time: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(hour).padStart(2, '0')}:00`,
        value: Number(temp.toFixed(1))
      })
    }

    data.push(...hourlyData)
  }

  return data
} 